home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / SystemColor.java < prev    next >
Text File  |  1998-09-22  |  12KB  |  374 lines

  1. /*
  2.  * @(#)SystemColor.java    1.8 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. /**
  17.  * A class to encapsulate symbolic colors representing the color
  18.  * of GUI objects on a system.  For systems which support the dynamic
  19.  * update of the system colors (when the user changes the colors)
  20.  * the actual RGB values of these symbolic colors will also change
  21.  * dynamically.  In order to compare the "current" RGB value of a SystemColor
  22.  * object with a non-symbolic Color object, getRGB() should be used
  23.  * rather than equals(). 
  24.  *
  25.  * @version     1.8, 07/01/98
  26.  * @author     Carl Quinn
  27.  * @author      Amy Fowler
  28.  */
  29. public final class SystemColor extends Color implements java.io.Serializable {
  30.  
  31.     /**
  32.      * The array index for the desktop background color.
  33.      */
  34.     public final static int DESKTOP = 0;
  35.  
  36.     /**
  37.      * The array index for the active caption background color.
  38.      */
  39.     public final static int ACTIVE_CAPTION = 1;
  40.  
  41.     /**
  42.      * The array index for the action caption text color.
  43.      */
  44.     public final static int ACTIVE_CAPTION_TEXT = 2;
  45.  
  46.     /**
  47.      * The array index for the active caption border color.
  48.      */
  49.     public final static int ACTIVE_CAPTION_BORDER = 3;
  50.  
  51.     /**
  52.      * The array index for the inactive caption background color.
  53.      */
  54.     public final static int INACTIVE_CAPTION = 4;
  55.  
  56.     /**
  57.      * The array index for the inactive caption text color.
  58.      */
  59.     public final static int INACTIVE_CAPTION_TEXT = 5;
  60.  
  61.     /**
  62.      * The array index for the inactive caption border color.
  63.      */
  64.     public final static int INACTIVE_CAPTION_BORDER = 6;
  65.  
  66.     /**
  67.      * The array index for the window background color.
  68.      */
  69.     public final static int WINDOW = 7;
  70.  
  71.     /**
  72.      * The array index for the window border color.
  73.      */
  74.     public final static int WINDOW_BORDER = 8;
  75.  
  76.     /**
  77.      * The array index for the window text color.
  78.      */
  79.     public final static int WINDOW_TEXT = 9;
  80.  
  81.     /**
  82.      * The array index for the menu background color.
  83.      */
  84.     public final static int MENU = 10;
  85.  
  86.     /**
  87.      * The array index for the menu text color.
  88.      */
  89.     public final static int MENU_TEXT = 11;
  90.  
  91.     /**
  92.      * The array index for the text background color.
  93.      */
  94.     public final static int TEXT = 12;
  95.  
  96.     /**
  97.      * The array index for the text text color.
  98.      */
  99.     public final static int TEXT_TEXT = 13;
  100.  
  101.     /**
  102.      * The array index for the text highlight color.
  103.      */
  104.     public final static int TEXT_HIGHLIGHT = 14;
  105.  
  106.     /**
  107.      * The array index for the text highlight text color.
  108.      */
  109.     public final static int TEXT_HIGHLIGHT_TEXT = 15;
  110.  
  111.     /**
  112.      * The array index for the text inactive text color.
  113.      */
  114.     public final static int TEXT_INACTIVE_TEXT = 16;
  115.  
  116.     /**
  117.      * The array index for the control background color.
  118.      */
  119.     public final static int CONTROL = 17;
  120.  
  121.     /**
  122.      * The array index for the control text color.
  123.      */
  124.     public final static int CONTROL_TEXT = 18;
  125.  
  126.     /**
  127.      * The array index for the control highlight color.
  128.      */
  129.     public final static int CONTROL_HIGHLIGHT = 19;
  130.  
  131.     /**
  132.      * The array index for the control light highlight color.
  133.      */
  134.     public final static int CONTROL_LT_HIGHLIGHT = 20;
  135.  
  136.     /**
  137.      * The array index for the control shadow color.
  138.      */
  139.     public final static int CONTROL_SHADOW = 21;
  140.  
  141.     /**
  142.      * The array index for the control dark shadow color.
  143.      */
  144.     public final static int CONTROL_DK_SHADOW = 22;
  145.  
  146.     /**
  147.      * The array index for the scrollbar background color.
  148.      */
  149.     public final static int SCROLLBAR = 23;
  150.  
  151.     /**
  152.      * The array index for the info background color.
  153.      */
  154.     public final static int INFO = 24;
  155.  
  156.     /**
  157.      * The array index for the info text color.
  158.      */
  159.     public final static int INFO_TEXT = 25;
  160.  
  161.     /**
  162.      * The number of system colors in the array.
  163.      */
  164.     public final static int NUM_COLORS = 26;
  165.     
  166.    /**
  167.      * The color of the desktop background.
  168.      */
  169.     public final static SystemColor desktop = new SystemColor((byte)DESKTOP);
  170.  
  171.     /**
  172.      * The background color for captions in window borders.
  173.      */
  174.     public final static SystemColor activeCaption = new SystemColor((byte)ACTIVE_CAPTION);
  175.  
  176.     /**
  177.      * The text color for captions in window borders.
  178.      */
  179.     public final static SystemColor activeCaptionText = new SystemColor((byte)ACTIVE_CAPTION_TEXT);
  180.  
  181.     /**
  182.      * The border color for captions in window borders.
  183.      */
  184.     public final static SystemColor activeCaptionBorder = new SystemColor((byte)ACTIVE_CAPTION_BORDER);
  185.  
  186.     /**
  187.      * The background color for inactive captions in window borders.
  188.      */
  189.     public final static SystemColor inactiveCaption = new SystemColor((byte)INACTIVE_CAPTION);
  190.  
  191.     /**
  192.      * The text color for inactive captions in window borders.
  193.      */
  194.     public final static SystemColor inactiveCaptionText = new SystemColor((byte)INACTIVE_CAPTION_TEXT);
  195.  
  196.     /**
  197.      * The border color for inactive captios in window borders.
  198.      */
  199.     public final static SystemColor inactiveCaptionBorder = new SystemColor((byte)INACTIVE_CAPTION_BORDER);
  200.  
  201.     /**
  202.      * The background color for windows.
  203.      */
  204.     public final static SystemColor window = new SystemColor((byte)WINDOW);
  205.  
  206.     /**
  207.      * The border color for windows.
  208.      */
  209.     public final static SystemColor windowBorder = new SystemColor((byte)WINDOW_BORDER);
  210.  
  211.     /**
  212.      * The text color for windows.
  213.      */
  214.     public final static SystemColor windowText = new SystemColor((byte)WINDOW_TEXT);
  215.  
  216.     /**
  217.      * The background color for menus.
  218.      */
  219.     public final static SystemColor menu = new SystemColor((byte)MENU);
  220.  
  221.     /**
  222.      * The text color for menus.
  223.      */
  224.     public final static SystemColor menuText = new SystemColor((byte)MENU_TEXT);
  225.  
  226.     /**
  227.      * The background color for text components.
  228.      */
  229.     public final static SystemColor text = new SystemColor((byte)TEXT);
  230.  
  231.     /**
  232.      * The text color for text components.
  233.      */
  234.     public final static SystemColor textText = new SystemColor((byte)TEXT_TEXT);
  235.  
  236.     /**
  237.      * The background color for highlighted text.
  238.      */
  239.     public final static SystemColor textHighlight = new SystemColor((byte)TEXT_HIGHLIGHT);
  240.  
  241.     /**
  242.      * The text color for highlighted text.
  243.      */
  244.     public final static SystemColor textHighlightText = new SystemColor((byte)TEXT_HIGHLIGHT_TEXT);
  245.  
  246.     /**
  247.      * The text color for inactive text.
  248.      */
  249.     public final static SystemColor textInactiveText = new SystemColor((byte)TEXT_INACTIVE_TEXT);
  250.  
  251.     /**
  252.      * The background color for control objects.
  253.      */
  254.     public final static SystemColor control = new SystemColor((byte)CONTROL);
  255.  
  256.     /**
  257.      * The text color for control objects.
  258.      */
  259.     public final static SystemColor controlText = new SystemColor((byte)CONTROL_TEXT);
  260.  
  261.     /**
  262.      * The regular highlight color for control objects.
  263.      */
  264.     public final static SystemColor controlHighlight = new SystemColor((byte)CONTROL_HIGHLIGHT);
  265.  
  266.     /**
  267.      * The light highlight color for control objects.
  268.      */
  269.     public final static SystemColor controlLtHighlight = new SystemColor((byte)CONTROL_LT_HIGHLIGHT);
  270.  
  271.     /**
  272.      * The regular shadow color for control objects.
  273.      */
  274.     public final static SystemColor controlShadow = new SystemColor((byte)CONTROL_SHADOW);
  275.  
  276.     /**
  277.      * The dark shadow color for control objects.
  278.      */
  279.     public final static SystemColor controlDkShadow = new SystemColor((byte)CONTROL_DK_SHADOW);
  280.  
  281.     /**
  282.      * The background color for scrollbars.
  283.      */
  284.     public final static SystemColor scrollbar = new SystemColor((byte)SCROLLBAR);
  285.  
  286.     /**
  287.      * The background color for info(help) text.
  288.      */
  289.     public final static SystemColor info = new SystemColor((byte)INFO);
  290.  
  291.     /**
  292.      * The text color for info(help) text.
  293.      */
  294.     public final static SystemColor infoText = new SystemColor((byte)INFO_TEXT);
  295.  
  296.     /*
  297.      * System colors with default initial values, overwritten by toolkit if 
  298.      * system values differ and are available.
  299.      */
  300.     private static int[] systemColors = {
  301.         0xFF005C5C,  // desktop = new Color(0,92,92);
  302.         0xFF000080,  // activeCaption = new Color(0,0,128);
  303.         0xFFFFFFFF,  // activeCaptionText = Color.white;
  304.         0xFFC0C0C0,  // activeCaptionBorder = Color.lightGray;
  305.         0xFF808080,  // inactiveCaption = Color.gray;
  306.         0xFFC0C0C0,  // inactiveCaptionText = Color.lightGray;
  307.         0xFFC0C0C0,  // inactiveCaptionBorder = Color.lightGray;
  308.         0xFFFFFFFF,  // window = Color.white;
  309.         0xFF000000,  // windowBorder = Color.black;
  310.         0xFF000000,  // windowText = Color.black;
  311.         0xFFC0C0C0,  // menu = Color.lightGray;
  312.         0xFF000000,  // menuText = Color.black;
  313.         0xFFC0C0C0,  // text = Color.lightGray;
  314.         0xFF000000,  // textText = Color.black;
  315.         0xFF000080,  // textHighlight = new Color(0,0,128);
  316.         0xFFFFFFFF,  // textHighlightText = Color.white;
  317.         0xFF808080,  // textInactiveText = Color.gray;
  318.         0xFFC0C0C0,  // control = Color.lightGray;
  319.         0xFF000000,  // controlText = Color.black;
  320.         0xFFFFFFFF,  // controlHighlight = Color.white;
  321.         0xFFE0E0E0,  // controlLtHighlight = new Color(224,224,224);
  322.         0xFF808080,  // controlShadow = Color.gray;
  323.         0xFF000000,  // controlDkShadow = Color.black;
  324.         0xFFE0E0E0,  // scrollbar = new Color(224,224,224);
  325.         0xFFE0E000,  // info = new Color(224,224,0);
  326.         0xFF000000,  // infoText = Color.black;
  327.     };
  328.  
  329.     /*
  330.      * JDK 1.1 serialVersionUID 
  331.      */
  332.     private static final long serialVersionUID = 4503142729533789064L;
  333.  
  334.     static {
  335.       updateSystemColors();
  336.     }
  337.  
  338.     /**
  339.      * called from <init> & toolkit to update the above systemColors cache
  340.      */
  341.     private static void updateSystemColors() {
  342.       Toolkit.getDefaultToolkit().loadSystemColors(systemColors);
  343.     }
  344.  
  345.     /**
  346.      * Create a symbolic color that represents an indexed entry into system
  347.      * color cache. Used by above static system colors.
  348.      */
  349.     private SystemColor(byte index) {
  350.         super(0, 0, 0);
  351.     value = index;
  352.     }
  353.  
  354.     /**
  355.      * Gets the "current" RGB value representing the symbolic color.
  356.      * (Bits 24-31 are 0xff, 16-23 are red, 8-15 are green, 0-7 are blue).
  357.      * @see java.awt.image.ColorModel#getRGBdefault
  358.      * @see java.awt.Color#getBlue(int)
  359.      * @see java.awt.Color#getGreen(int)
  360.      * @see java.awt.Color#getRed(int)
  361.      */
  362.     public int getRGB() {
  363.     return systemColors[value];
  364.     }
  365.  
  366.     /**
  367.      * Returns the String representation of this Color's values.
  368.      */
  369.     public String toString() {
  370.         return getClass().getName() + "[i=" + (value) + "]";
  371.     }
  372.  
  373. }
  374.